function assign  (oldData,newData,add=false){
    if (typeof(oldData)!='object') return oldData;
  
    for(let key in newData){
        if (oldData[key]!=undefined){
          if (newData && newData[key]!=undefined && newData[key]!=null){
             oldData[key] = newData[key];
          } 
        }else{
            if (add) oldData[key] = newData[key];
        }
    }
    
    return oldData;
  }
  
  
  function esc(fun){
    if (window.biEscKeyList==undefined) {
        window.biEscKeyList = [];   
    }
    window.biEscKeyList.push(fun);
  }
  
  function enter(fun){
    
    if (window.biEnterKeyList==undefined) {
        window.biEnterKeyList = [];   
    }
    window.biEnterKeyList.push(fun);
  }
  
  if (window.biKeyupInit==undefined || window.biKeyupInit==false){
    window.biKeyupInit = true;
    document.addEventListener('keyup', (e)=>{       
        if (window.biEscKeyList!=undefined || window.biEnterKeyList!=undefined){
          if (e.key=="Escape"){
            e.stopPropagation();
            fun =   window.biEscKeyList.pop();
            if (typeof(fun)=="function") fun(); 
            
          }
      
          if (e.key=="Enter"){
            e.stopPropagation();
             fun = window.biEnterKeyList.pop();
             if (typeof(fun)=="function") fun(); 
          }
        }
       
    });
  }
  
  
 
  
  
/**
  * 防抖函数
  * 
  * @param {function} callback 
  * @param {number} delay 
  * @returns 
  */
function debounce(callback, delay) {
  let timer = null

// 所以这个函数就可以使用...运算符收集js自动添加的参数到一个数组中
  return function _debounce(...arg) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      // 通过apply绑定this和传递参数，apply第二个参数正好是传数组嘛
      callback.apply(this, arg)
    }, delay)
  }
}
  
  export default {
    assign,esc,enter,debounce
  }